package org.stvd.entities.admin;

import java.text.ParseException;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.stvd.core.annotation.serializer.DateTimeSerializer;
import org.stvd.core.util.DateUtil;
import org.stvd.entities.base.BaseEntity;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

@Entity
@Table(name = "loginfo")
public class Loginfo extends BaseEntity{
    
    private static final long serialVersionUID = 4909325541297484068L;
    private String log_id;
    private String guid;
    private String log_type;
    private String log_type2;
    private String user_id;
    private String user_name;
    private String role_id;
    private String role_name;
    private String dep_id;
    private String dep_name;
    private Date oper_datetime;
    private String ip_address;
    private String computer;
    private String log_content;
    private String log_old;
    private String log_new;
    private String remark;
    
    //辅助查询用，开始结束时间
    private String begin_date ;
    private String end_date ;
    private Date beginDate;
    private Date endDate;
    
    @Id  
    @Column(name="log_id",nullable=false) 
    public String getLog_id() {
        return log_id;
    }
    public void setLog_id(String log_id) {
        this.log_id = log_id;
    }
    @Column(name="guid",nullable=false) 
    public String getGuid() {
        return guid;
    }
    public void setGuid(String guid) {
        this.guid = guid;
    }
        
    @Column(name="log_type",nullable=false) 
    public String getLog_type() {
        return log_type;
    }
    public void setLog_type(String log_type) {
        this.log_type = log_type;
    }
    
    @Column(name="log_type2",nullable=false) 
    public String getLog_type2() {
        return log_type2;
    }
    public void setLog_type2(String log_type2) {
        this.log_type2 = log_type2;
    }
    
    @Column(name="user_id",nullable=true) 
    public String getUser_id() {
        return user_id;
    }
    public void setUser_id(String user_id) {
        this.user_id = user_id;
    }
    
    @Column(name="user_name",nullable=true) 
    public String getUser_name() {
        return user_name;
    }
    public void setUser_name(String user_name) {
        this.user_name = user_name;
    }
    
    @Column(name="role_id",nullable=true) 
    public String getRole_id() {
        return role_id;
    }
    public void setRole_id(String role_id) {
        this.role_id = role_id;
    }
    
    @Column(name="role_name",nullable=true) 
    public String getRole_name() {
        return role_name;
    }
    public void setRole_name(String role_name) {
        this.role_name = role_name;
    }
    
    @Column(name="dep_id",nullable=true) 
    public String getDep_id() {
        return dep_id;
    }
    public void setDep_id(String dep_id) {
        this.dep_id = dep_id;
    }
    
    @Column(name="dep_name",nullable=true) 
    public String getDep_name() {
        return dep_name;
    }
    public void setDep_name(String dep_name) {
        this.dep_name = dep_name;
    }
    
    @Column(name="oper_datetime",nullable=true) 
    @JsonSerialize(using=DateTimeSerializer.class)
    public Date getOper_datetime() {
        return oper_datetime;
    }
    public void setOper_datetime(Date oper_datetime) {
        this.oper_datetime = oper_datetime;
    }
    
    @Column(name="ip_address",nullable=true) 
    public String getIp_address() {
        return ip_address;
    }
    public void setIp_address(String ip_address) {
        this.ip_address = ip_address;
    }
    
    @Column(name="computer",nullable=true) 
    public String getComputer() {
        return computer;
    }
    public void setComputer(String computer) {
        this.computer = computer;
    }
    
    @Column(name="log_content",nullable=false) 
    public String getLog_content() {
        return log_content;
    }
    public void setLog_content(String log_content){
        this.log_content = log_content;
    }
    
    @Column(name="log_old",nullable=true) 
    public String getLog_old() {
        return log_old;
    }
    public void setLog_old(String log_old){
        this.log_old = log_old;
    }
    
    @Column(name="log_new",nullable=true) 
    public String getLog_new() {
        return log_new;
    }
    public void setLog_new(String log_new){
        this.log_new = log_new;
    }
    
    @Column(name="remark",nullable=true) 
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark){
        this.remark = remark;
    }
    
    @Transient
    public String getBegin_date() {
        return begin_date;
    }
    public void setBegin_date(String begin_date) {
        this.begin_date = begin_date;
        try {
            if(this.begin_date == null || this.begin_date.equals("")){
                this.beginDate = DateUtil.Y2DTIME_FORMAT.parse("1900-01-01 00:00:00");
            } else {
                this.beginDate = DateUtil.Y2DTIME_FORMAT.parse(begin_date+" 00:00:00");
            }
        } catch (ParseException e) {
            try {
                this.beginDate = DateUtil.Y2DTIME_FORMAT.parse("1900-01-01 00:00:00");
            } catch (ParseException e1) {
                e1.printStackTrace();
            }
        }
    }
    
    @Transient
    public String getEnd_date() {
        return end_date;
    }
    public void setEnd_date(String end_date) {
        this.end_date = end_date;
        try {
            if(this.end_date == null || this.end_date.equals("")){
                this.endDate = DateUtil.Y2DTIME_FORMAT.parse("9999-12-31 23:59:59");
            } else {
                this.endDate = DateUtil.Y2DTIME_FORMAT.parse(begin_date+" 23:59:59");
            }
        } catch (ParseException e) {
            try {
                this.endDate = DateUtil.Y2DTIME_FORMAT.parse("9999-12-31 23:59:59");
            } catch (ParseException e1) {
                e1.printStackTrace();
            }
        }
        this.end_date = end_date;
    }
    
    @Transient
    public Date getBeginDate() {
        return beginDate;
    }
    public void setBeginDate(Date beginDate) {
        this.beginDate = beginDate;
    }
    
    @Transient
    public Date getEndDate() {
        return endDate;
    }
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
    
}